<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JS作业</title>

    <style>
        *{margin: 0;padding:0;}
        div{
            width: 200px;
            height: 200px;
        }
        #div1{background: red;}
        #div2{background: blue;display: none;}
    </style>

    <script>
        function $(id){return document.getElementById(id);}
        window.onload=function (){

            $("but2").addEventListener("click",function (){
                $("div2").style.display='block';
                $("div1").style.display='none';
                })

            $("but1").addEventListener("click",function (){
                    $("div1").style.display='block';
                    $("div2").style.display='none';
                })
        }
    </script>
</head>
<body>
    <button id="but1">显示DIV1</button>
    <button id="but2">显示DIV2</button>
    <div style="border: 1px solid cyan;">
        <div id="div1"></div>
        <div id="div2"></div>
    </div>
</body>
</html>